<!--
 * @Descripttion: 
 * @version: 
 * @Author: Peanut
 * @Date: 2024-04-20 11:30:02
 * @LastEditors: Peanut
 * @LastEditTime: 2024-04-29 11:13:28
-->
<template>
  <div class="homePage">
    <el-container>
      <el-main>
        <el-button style="margin-bottom: 20px" @click="openEditPop"
          >点击修改公告信息</el-button
        >
        <el-card class="accounceBox">
          <i
            class="el-icon-message-solid"
            style="margin-right: 18px; font-size: 20px"
            >公告：</i
          >
          <div class="scrolling-text">
            <span>{{ announce }}</span>
          </div>
        </el-card>
        <h1>我的信息</h1>

        <el-card style="width: 40%">
          <p>
            <i class="el-icon-s-home" style="margin-right: 18px"></i
            >用户名称：{{ name }}
          </p>
          <p>
            <i class="el-icon-s-custom" style="margin-right: 18px"></i
            >用户类型：{{
              userType == "user"
                ? "用户"
                : userType == "admin"
                ? "管理员"
                : "未知"
            }}
          </p>
          <!-- <p>
            <i class="el-icon-location" style="margin-right: 18px"></i
            >坐标位置：地球
          </p>
          <p>
            <i class="el-icon-s-promotion" style="margin-right: 18px"></i>email:
            66666666
          </p> -->
        </el-card>
      </el-main>
      <el-dialog
        title="修改公告信息"
        :visible.sync="amendAnnounceShow"
        width="600px"
        height="400px"
      >
        <div class="amendPage">
          <el-form label-width="100px" class="demo-ruleForm">
            <el-form-item label="修改后公告" prop="name">
              <el-input
                type="textarea"
                :rows="4"
                v-model="newAnnounce"
                placeholder="请输入更新的公告"
                prefix-icon="el-icon-lollipop"
              ></el-input>
            </el-form-item>
          </el-form>
        </div>
        <div slot="footer" class="dialog-footer">
          <el-button size="small" type="primary" @click="handleClose"
            >确 定</el-button
          >
        </div>
      </el-dialog>
    </el-container>
  </div>
</template>

<script>
export default {
  name: "home",
  components: {},
  data() {
    return {
      name: JSON.parse(sessionStorage.getItem("userData")).name,
      userType: JSON.parse(sessionStorage.getItem("userData")).role,
      amendAnnounceShow: false,
      announce: "",
      announceId: 0,
      newAnnounce: "",
      // ggList: [],
    };
  },
  mounted() {
    this.getAccouncement();
  },
  methods: {
    //页面加载时调用的公告展示接口
    getAccouncement() {
      axios.get("http://localhost:8080/user/showAnnouncement").then((res) => {
        if (res.code == 1) {
          this.announce = res.data.text;
          this.announceId = res.data.id; //将公告id存一下，修改公告会调用此参数
          // this.ggList.push({ noticeContent: res.data.text });
        }
      });
    },
    openEditPop() {
      this.amendAnnounceShow = true;
    },
    handleClose() {
      if (this.newAnnounce != "") {
        axios
          .post("http://localhost:8080/admin/updateAnnouncement", {
            text: this.newAnnounce,
            id: this.announceId,
          })
          .then((res) => {
            if (res.code == 1) {
              this.amendAnnounceShow = false;
              this.$message({
                message: "修改成功！！",
                type: "success",
              });
              this.getAccouncement();
            }
          });
      } else {
        this.$message({
          message: "请输入公告！",
          type: "error",
        });
      }
    },
  },
};
</script>

<style scoped lang="scss">
.homePage {
  .accounceBox {
    /deep/.el-card__body {
      width: 100%;
      display: flex;
      align-items: center;
      i {
        width: 10%;
      }
      .scrolling-text {
        overflow: hidden;
        white-space: nowrap;
        width: 85%;
        /* text-align: center; */
      }

      .scrolling-text span {
        font-size: 20px;
        display: inline-block;
        padding-left: 100%;
        animation: marquee 20s linear infinite; /* 调整动画时长和效果 */
      }

      @keyframes marquee {
        0% {
          transform: translateX(0);
        }
        100% {
          transform: translateX(-100%);
        }
      }
    }
  }
}
</style>
